package benny_driving_ser.util;

import java.net.URI;
import java.net.URLEncoder;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import benny_driving_ser.constant.URLConstant;

@SuppressWarnings("deprecation")
public class SendSMSUtil {
	private SendSMSUtil() {
	}

	private static class SendSMSUtilHolder {
		private static SendSMSUtil instance = new SendSMSUtil();
	}

	public static SendSMSUtil getInstance() {
		return SendSMSUtilHolder.instance;
	}

	public boolean sendSMS(String tel, String text) {
		String url = URLConstant.SMS_BASE_URL + "smsMob=" + tel + "&smsText="
				+ text;
		try {
			DefaultHttpClient httpClient = new DefaultHttpClient();
			HttpGet httpGet = new HttpGet();
			httpGet.setURI(new URI(url));
			HttpResponse httpresponse = httpClient.execute(httpGet);
			HttpEntity entity = httpresponse.getEntity();
			String res = EntityUtils.toString(entity);
			if ("1".equals(res.trim()))
				return true;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}

}
